[GEN][ZH] Change reference counter implementation for StateMachine to avoid mismatch with Retail#1078
Conversation
|
I just checked again with this branch and the change works as intended: replay |
|
Replicated in Generals |
|
Is the crash that 890 fixed originally still fixed, could you verify that? |
Tested. Is fixed. |
| WWASSERT(NumRefs != IntegerType(0)); | ||
| if (--NumRefs == IntegerType(0)) | ||
| { | ||
| deleteFunction(const_cast<ObjectType*>(objectToDelete)); |
There was a problem hiding this comment.
What's the purpose of having a const function and mutable member variable? I see the consistency with RefCountClass, but I don't see why it's needed there either.
There was a problem hiding this comment.
This is required so that const objects can still do reference counting. Otherwise we cannot pass around const objects, or destroy them.
There was a problem hiding this comment.
Wouldn't it make more sense if those const objects use a mutable RefCountValue member variable?
There was a problem hiding this comment.
The const_cast needs to be somewhere. I think it is better if it is buried here in this class and not in all code that interacts with this class.
There was a problem hiding this comment.
Does the const_cast need to be anywhere if the RefCountValue is mutable?
struct RefCountValue
{
int NumRefs = 0;
void Release_Ref()
{
--NumRefs;
}
};
struct StateMachine
{
void Release_Ref() const
{
m_refCount.Release_Ref();
}
mutable RefCountValue m_refCount;
};
int main()
{
const StateMachine machine;
machine.Release_Ref();
}
Is this not a representative minimal example?
There was a problem hiding this comment.
Yes, const cast happens when passing this pointer to delete function.
There was a problem hiding this comment.
Right. Maybe you can add a comment for RefCountValue::Release_Ref that explains the use of const member function and const_cast on the object that'll be deleted.
There was a problem hiding this comment.
Ok. Added a bunch of comments in EA/Westwood comment style.
… avoid mismatch with Retail (TheSuperHackers#1078)
… avoid mismatch with Retail (TheSuperHackers#1078)
This changes the reference counter implementation for
StateMachineto avoid mismatch with Retail.The previous reference counter changes the struct layout of
StateMachine, which then changed the generated assembler code of many functions that interact withStateMachine.TODO